; ----------------------------------------------------------------------------------------------------------
; OPCODE TABLE - must be aligned to page (later to use space more efficiently put it in a fixed location)

; TODO
;  figure out how to not require all opcodes to be defined in this file.

opcode = 0


align 256  ;this speeds it up
opcodes:
;	.dsw 128

macro op sub
; enum opcodes+opcode
	.dw sub-1
; ende
	opcode = opcode+2
endm

	end = opcode
	op _end
	lit = opcode
	op _lit
	twolit = opcode
	op _twolit
	fetch = opcode
	op _fetch
	store = opcode
	op _store
	plusstore = opcode
	op _plusstore
	alit = opcode
	op _alit
	plus = opcode
	op _plus
	sbtrkt = opcode
	op _sbtrkt
	invert = opcode
	op _invert
	negate = opcode
	op _negate
	or = opcode
	op _vm_or
	xor = opcode
	op _vm_xor
	andd = opcode
	op _vm_and
	dup = opcode
	op _dup
	drop = opcode
	op _drop
	over = opcode
	op _over
	swap = opcode
	op _swap
	nip = opcode
	op _nip
	vpstore = opcode
	op _vpstore
	vstore = opcode
	op _vstore
	oneplus = opcode
	op _oneplus
	oneminus = opcode
	op _oneminus
	twodiv = opcode
	op _twodiv
	twomul = opcode
	op _twomul
	fetchplus = opcode
	op _fetchplus
	storeplus = opcode
	op _storeplus
	fetcha = opcode
	op _fetcha
	storea = opcode
	op _storea
	zless = opcode
	op zless
	less = opcode
	op _less
	zgreater = opcode
	op _zgreater
	greater = opcode
	op _greater
	uless = opcode
	op _uless
	ugreater = opcode
	op _ugreater
	iff = opcode
	op _iff
	mif = opcode
	op _mif
	for = opcode
	op _for
	next = opcode
	op _next
	branch = opcode
	op _branch
	while = opcode
	op _while
	metaspr = opcode
	op _metaspr
	exit = opcode
	op _exit
	call = opcode
	op _call
	plusfetch = opcode
	op _plusfetch
	plusa = opcode
	op _plusa



; ----------------------------------------------------------------------
macro num n
	.db lit
	.db n
endm

; doubles are pushed low and then high. this is because of the 6502 stack being little-endian.
macro dnum n
	.db twolit
	.dw n
endm

macro vmif label
	.db iff
	.db ((label)-$)
endm